import requests
import re
from  lxml import etree


base_url = 'http://www.66ip.cn/'


# headers = {
#     "User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.110 Safari/537.36"
# }
response = requests.get(base_url)

response.encoding = 'gbk'

html = response.text
html2 = etree.HTML(html)
# print(html)
#
# pat = re.compile(r'<tr><td>(.*?)</td>.*?</tr>')
# ip = pat.findall(html)
res = html2.xpath('//table[@bordercolor="#6699ff"]//tr/td/text()')
print(res)

dyx = []
for i in range(0,len(res),5):
    dyx.append(res[i:i+5])
    print(dyx)
    newdic = {}
    for j in range(0,len(dyx)):
        newdic['ip'] = str(dyx)[0]
        newdic['port'] = str(dyx)[1]
        newdic['httptype'] = str(dyx)[3]
        dyx.append(newdic)
print(newdic)



